#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import time

import cv2

imageFolder = "mijing"


def get_screenshot(i):
    # name = '{:05d}_{}'.format(i, int(time.time()))
    name = '{:05d}'.format(i)
    os.system('adb shell screencap -p /sdcard/book/image/{}.png'.format(name))
    os.system('adb pull /sdcard/book/image/{}.png {}/{}.png'.format(name, imageFolder, name))
    os.system('adb shell rm /sdcard/book/image/{}.png'.format(name))
    return name


def click(location):
    cmd = 'adb shell input swipe %s %s %s %s 100' % (location[0], location[1], location[0], location[1])
    print('%s' % (cmd))
    os.system(cmd)


def test1():
    name = get_screenshot(19)
    # path = os.path.join(imageFolder, name + '.png')
    # img_rgb = cv2.imread(path)
    # img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    # cv2.imwrite('{}/{}_last.png'.format(imageFolder, name), img_gray)
    # time.sleep(1.5)


def test2():
    for i in range(100000):
        click([560, 650])
        time.sleep(0.2)
        click([1100, 450])
        time.sleep(0.2)
        click([1220, 660])
        time.sleep(0.2)


if __name__ == '__main__':
    test2()
    # get_screenshot(1)
